#   Copyright 2006 Jerome Lacoste (jerome@coffeebreaks.org)
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
class InitialTables < ActiveRecord::Migration

  def self.up
    create_table "assignments", :force => true do |t|
      t.column "project_id", :integer, :default => 0, :null => false
      t.column "user_id", :integer, :default => 0, :null => false
    end

    add_index "assignments", ["user_id"], :name => "fk_assignment_worker"

    create_table "clients", :force => true do |t|
      t.column "owner_id", :integer, :default => 0, :null => false
      t.column "short", :string, :limit => 5, :default => "", :null => false
      t.column "name", :string, :default => "", :null => false
      t.column "url", :string, :default => "", :null => false
    end

    add_index "clients", ["owner_id"], :name => "fk_client_owner"

    create_table "projects", :force => true do |t|
      t.column "client_id", :integer, :default => 0, :null => false
      t.column "short", :string, :limit => 5, :default => "", :null => false
      t.column "name", :string, :limit => 100, :default => "", :null => false
    end

    add_index "projects", ["client_id"], :name => "fk_project_client"

    create_table "users", :force => true do |t|
      t.column "name", :string, :default => "", :null => false
      t.column "short", :string, :limit => 4, :default => "", :null => false
      t.column "hashed_password", :string, :limit => 40
    end

    create_table "worklogs", :force => true do |t|
      t.column "project_id", :integer, :default => 0, :null => false
      t.column "worker_id", :integer, :default => 0, :null => false
      t.column "done_at", :datetime, :null => false
      t.column "duration", :float, :limit => 4, :default => 0.0, :null => false
      t.column "description", :text, :default => "", :null => false
    end

    add_index "worklogs", ["project_id"], :name => "fk_worklog_project"
    add_index "worklogs", ["worker_id"], :name => "fk_worklog_worker"

  end

  def self.down
    remove_index "projects", :name => "fk_project_client"
    remove_index "clients", :name => "fk_client_owner"
    remove_index "assignments", :name => "fk_assignment_worker"
    remove_index "worklogs", :name => "fk_worklog_project"
    remove_index "worklogs", :name => "fk_worklog_worker"

    drop_table :worklogs
    drop_table :assignments
    drop_table :projects
    drop_table :clients
    drop_table :users
  end
end
